package com.ssrs.batch.core.factory;

import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersIncrementer;

/**
 * 批处理运行自增ID
 *
 * @author ssrs
 */
public class OpenRunIdIncrementer implements JobParametersIncrementer {
    private String key = "run.id";

    public OpenRunIdIncrementer() {
    }

    public void setKey(String key) {
        this.key = key;
    }

    @Override
    public JobParameters getNext(JobParameters parameters) {
        JobParameters params = parameters != null ? parameters : new JobParameters();
        long id = params.getLong(key, new Long(0)) + 1L;
        return (new JobParametersBuilder(params)).addLong(key, id).toJobParameters();
    }
}
